package org.the.gsdo.server;

import org.the.gsdo.client.GreetingService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

// we cannot inject into a servlet
// we use it as a facade to the ...Manager classes
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService {

	@Override
	public String greetServer(String input) throws IllegalArgumentException {
		// javax.inject.Provider is buggy in spring
		// using homemade BeanProvider (see ApplicationConfiguration)
		return BeanProvider.getBean(GreetingManager.class).greetServer(input, getServerInfo(), getUserAgent());
	}

	protected String getUserAgent() {
		String userAgent = getThreadLocalRequest().getHeader("User-Agent");
		return userAgent;
	}

	protected String getServerInfo() {
		String serverInfo = getServletContext().getServerInfo();
		return serverInfo;
	}

}
